import { RJSFSchema, UiSchema } from '@rjsf/utils';
import { CollapseTemplate } from 'nextcae-base';
import { i18n } from '@/common/utils';
import { SelectionPickField } from '@/components/FieldTemplate/SelectionPickField';
export enum ModeType {
  OGrid = 'OGrid',
  Radial = 'Radial',
}
export enum ElementTypes {
  Tri = 'Tri',
  Quad = 'Quad',
}
export const schema: RJSFSchema = {
  type: 'object',
  properties: {
    Selection: {
      type: 'object',
      title: i18n.t('Selection'),
      properties: {
        source: {
          title: i18n.t('Source'),
          type: 'array',
          ...{
            'x-options': [
              {
                const: ['node', 'point'],
                title: i18n.t('节点'),
              },
            ],
          },
        },
      },
    },
    Option: {
      type: 'object',
      title: i18n.t('Option'),
      properties: {
        elementType: {
          title: i18n.t('网格类型'),
          type: 'string',
          oneOf: [
            {
              const: ElementTypes.Tri,
              title: i18n.t('三角形网格'),
            },
            {
              const: ElementTypes.Quad,
              title: i18n.t('四边形网格'),
            },
          ],
        },
      },
    },
    AddTo: {
      type: 'object',
      title: i18n.t('添加到'),
      properties: {
        property: {
          title: i18n.t('属性'),
          type: 'number',
          ...{
            JsonPath: 'FE Structure.PROPERTY',
            hasAdd: true,
            hasDefault: true,
            args: { type: 'property', c: 'property.new' },
            params: { pType: 'shell', color: 0x856805, type: 0 },
          },
        },
        part: {
          title: i18n.t('部件'),
          type: 'number',
          ...{
            JsonPath: 'Part.PART',
            hasAdd: true,
            hasDefault: true,
            args: { c: 'part.new' },
            params: { type: 'part' },
          },
        },
      },
    },
  },
};

export const uiSchema: UiSchema = {
  Selection: {
    'ui:FieldTemplate': CollapseTemplate,
    'ui:layout': [1, 2],
    'ui:options': {
      label: false, // 不显示 label
    },
    source: {
      'ui:field': SelectionPickField,
      'ui:focused': true,
    },
  },
  Option: {
    'ui:FieldTemplate': CollapseTemplate,
    'ui:layout': [1, 2],
    'ui:options': {
      label: false, // 不显示 label
    },
    elementType: {
      'ui:field': 'selectionField',
    },
  },
  AddTo: {
    'ui:FieldTemplate': CollapseTemplate,
    'ui:layout': [1, 2],
    'ui:options': {
      label: false, // 不显示 label
    },
    property: {
      'ui:field': 'partMaterialField',
    },
    part: {
      'ui:field': 'partMaterialField',
    },
  },
};
